import { createStore, Store } from 'vuex'
import { InjectionKey } from 'vue'

export type State = {
  counter: number
}

// 1.创建一个injectionKey
export const key: InjectionKey<Store<State>> = Symbol()

export default createStore({
  state: {
    counter: 1
  },
  getters: {},
  mutations: {
    addCounter (state, step) {
      state.counter += step
    }
  },
  actions: {
    addCounter ({ state, commit }, value) {
      commit('addCounter', value)
    }
  },
  modules: {}
})